﻿@{
    Layout = null;
    ViewBag.Title = "角色授权范围明细——公路工程建设项目造价全过程管理系统";
}
@model DotNet.Model.MyEntity.Base_Role
<script type="text/javascript">

    //----------------------角色-----------------------------
    var zNodes_permission_role = [];
    var zTree_permission_role;
    var setting_permission_role;
    setting_permission_role = {
        checkable: true,
        editable: false,
        checkedCol: "Checked",
        async: true,
        asyncUrl: "/Permission/Role/GetRoleByzTree/0",
        nameCol: "Realname",
        open: false,
        treeNodeKey: "Id",
        treeNodeParentKey: "ParentId",
        asyncDataFilter: zTreeOnAsyncSuccess_Permission_role_ajaxDataFilter,
        callback: {
            asyncSuccess: zTreeOnAsyncSuccess_permission_role_roleSelect,
            click: zTreeOnClick_permission_role_roleSelect
        }
    };


    //绑定数据之前对数据进行预处理
    function zTreeOnAsyncSuccess_Permission_role_ajaxDataFilter(treeId, parentNode, childNodes) {
        if (childNodes) {
            var templist = $("#Permission_role_hidden_rolelistID").val().split(',');
            for (var i = 0; i < childNodes.length; i++) {
                for (var j = 0; j < templist.length; j++) {
                    if (childNodes[i].Id == templist[j]) {
                        childNodes[i].Checked = true;
                    }
                }
            }
        }
        return childNodes;
    }

    function zTreeOnAsyncSuccess_permission_role_roleSelect(event, treeId, treeNode, msg) {
        //异步成功
    }

    function zTreeOnClick_permission_role_roleSelect(event, treeId, treeNode) {
        //点击事件
    }
    //-----------------------------------------------------------------

    //--------------------组织机构--------------------------------------
    var zNodes_Permission_role_SelectOrganize = [];

    var zNodes_Permission_role_SelectOrganize;
    var setting_Permission_role_SelectOrganize;

    setting_Permission_role_SelectOrganize = {
        checkable: true,
        async: true,
        isSimpleData: true,
        asyncUrl: "/Permission/Organize/GetOrganizeNodes/2",  //获取节点数据的URL地址
        //asyncDataFilter: ajaxDataFilter,
        nameCol: "Name",
        open: true,
        treeNodeKey: "Id",
        treeNodeParentKey: "ParentId",
        asyncDataFilter: zTreeOnAsyncSuccess_Permission_Organize_ajaxDataFilter,
        callback: {
            //             beforeAsync: zTreeBeforeAsync,
            asyncSuccess: zTreeOnAsyncSuccess_Permission_Organize_SelectOrganize,
            //             asyncError: zTreeOnAsyncError,
            click: zTreeOnClick_Permission_Organize_SelectOrganize
        }
    };

    //绑定数据之前对数据进行预处理
    function zTreeOnAsyncSuccess_Permission_Organize_ajaxDataFilter(treeId, parentNode, childNodes) {
        if (childNodes) {
            var templist = $("#Permission_role_hidden_organizeID").val().split(',');
            for (var i = 0; i < childNodes.length; i++) {
                for (var j = 0; j < templist.length; j++) {
                    if (childNodes[i].Id == templist[j]) {
                        childNodes[i].checked = true;
                    }
                }
            }
        }
        return childNodes;
    }

    function zTreeOnAsyncSuccess_Permission_Organize_SelectOrganize(event, treeId, treeNode, msg) {
        //异步成功
        SetCheckedByzTree(zNodes_Permission_role_SelectOrganize, "Id", $("#Permission_role_hidden_organizeID").val());
    }

    //树的单击事件
    function zTreeOnClick_Permission_Organize_SelectOrganize(event, treeId, treeNode) {
        //alert(treeNode.Id);

    }
    //-------------------------------------------------------------------

    //    //-----------------------模块菜单-------------------------------------去除模块与操作权限的二次授权 WS 2011.11.2
    //        var zNodes_Permission_role_Module = [];

    //        var zTree_Permission_role_Module;
    //           var setting_Permission_role_Module;

    //        setting_Permission_role_Module = {
    //            checkable: true,
    //            async: true,
    //            isSimpleData: true,
    //            asyncUrl: "/Permission/Module/GetModuleMenus",  //获取节点数据的URL地址
    //            //asyncDataFilter: ajaxDataFilter,
    //            nameCol: "FullName",
    //            open: true,
    //            treeNodeKey: "Id",
    //            treeNodeParentKey: "ParentId",
    //            asyncDataFilter:zTreeOnAsyncSuccess_Permission_Module_ajaxDataFilter,
    //            callback: {
    //                //             beforeAsync: zTreeBeforeAsync,
    //                asyncSuccess: zTreeOnAsyncSuccess_Permission_Module_SelectTree,
    //                //             asyncError: zTreeOnAsyncError,
    //                click: zTreeOnClick_Permission_Module_SelectTree
    //            }
    //        };

    //        //绑定数据之前对数据进行预处理
    //        function zTreeOnAsyncSuccess_Permission_Module_ajaxDataFilter(treeId, parentNode, childNodes)
    //        {
    //            if(childNodes)
    //            {
    //                var templist= $("#Permission_role_hidden_modulelistID").val().split(',');
    //                for(var i =0; i < childNodes.length; i++) {
    //                    for(var j=0;j<templist.length;j++)
    //                    {
    //                        if(childNodes[i].Id==templist[j])
    //                        {
    //                            childNodes[i].checked=true;
    //                        }
    //                    }
    //                }
    //            }
    //            return childNodes;
    //        }

    //        function zTreeOnAsyncSuccess_Permission_Module_SelectTree(event, treeId, treeNode, msg) {
    //            //异步成功
    //            SetCheckedByzTree(zTree_Permission_role_Module,"Id",$("#Permission_role_hidden_modulelistID").val());
    //        }

    //        //树的单击事件
    //        function zTreeOnClick_Permission_Module_SelectTree(event, treeId, treeNode) {
    //            //alert(treeNode.Id);
    //        }
    //    //--------------------------------------------------------------------

    //    //-----------------------操作权限--------------------------------------
    //    var zNodes_Permission_role_PermissionItem = [];

    //    var zTree_Permission_role_PermissionItem;
    //    var setting_Permission_role_PermissionItem;

    //    setting_Permission_role_PermissionItem = {
    //        checkable: true,
    //        async: true,
    //        isSimpleData: true,
    //        asyncUrl: "/Permission/PermissionItem/GetPermissionItems",  //获取节点数据的URL地址
    //        //asyncDataFilter: ajaxDataFilter,
    //        nameCol: "FullName",
    //        open: true,
    //        treeNodeKey: "Id",
    //        treeNodeParentKey: "ParentId",
    //        asyncDataFilter:zTreeOnAsyncSuccess_Permission_PermissionItem_ajaxDataFilter,
    //        callback: {
    //            //             beforeAsync: zTreeBeforeAsync,
    //            asyncSuccess: zTreeOnAsyncSuccess_Permission_PermissionItem_SelectTree,
    //            //             asyncError: zTreeOnAsyncError,
    //            click: zTreeOnClick_Permission_PermissionItem_SelectTree
    //        }
    //    };

    //    //绑定数据之前对数据进行预处理
    //    function zTreeOnAsyncSuccess_Permission_PermissionItem_ajaxDataFilter(treeId, parentNode, childNodes)
    //    {
    //        if(childNodes)
    //        {
    //            var templist= $("#Permission_role_hidden_permissionitemlistID").val().split(',');
    //            for(var i =0; i < childNodes.length; i++) {
    //                for(var j=0;j<templist.length;j++)
    //                {
    //                    if(childNodes[i].Id==templist[j])
    //                    {
    //                        childNodes[i].checked=true;
    //                    }
    //                }
    //            }
    //        }
    //        return childNodes;
    //    }

    //    function zTreeOnAsyncSuccess_Permission_PermissionItem_SelectTree(event, treeId, treeNode, msg) {
    //        //异步成功
    //        SetCheckedByzTree(zTree_Permission_role_PermissionItem,"Id",$("#Permission_role_hidden_permissionitemlistID").val());
    //    }

    //    //树的单击事件
    //    function zTreeOnClick_Permission_PermissionItem_SelectTree(event, treeId, treeNode) {
    //        //alert(treeNode.Id);
    //    }
    //---------------------------------------------------------------------

    //给指定的zTree设置选中项
    function SetCheckedByzTree(ParmszTreeID, Parmskey, Parmsvalue) {
        //ParmszTreeID.cancelSelectedNode();
        var tempList = Parmsvalue.split(',');
        for (var i = 0; i < tempList.length; i++) {
            ParmszTreeID.selectNode(ParmszTreeID.getNodeByParam(Parmskey, tempList[i]));
        }
    }
    //已采用ViewBag的方式传值 
    //    //页面初始化事件
    //    function pageload()
    //    {
    //        //在页面加载完成后，通过AJAX方式获取所需值用JS选中对应的checkbox
    //        var temp_page_load_roleID = @Model.Id;
    //        $.ajax({
    //            url:"/Permission/Role/GetLoadValue",
    //            type:"post",
    //            dataType:"json",
    //            data:{"roleID":temp_page_load_roleID},
    //            success:function(data){
    //                if(data.type=="200")
    //                {
    //                    $("#Permission_role_hidden_rolelistID").val(data.roles);
    //                    $("#Permission_role_hidden_organizeID").val(data.organize);
    //                    $("#Permission_role_hidden_modulelistID").val(data.module);
    //                    $("#Permission_role_hidden_permissionitemlistID").val(data.permissionitem);
    //                }
    //                else
    //                {
    //                    alertMsg.error("获取数据失败，请稍后再试");
    //                    $.pdialog.closeCurrent();
    //                }
    //            },
    //            error:function(e)
    //            {
    //                alertMsg.error("获取数据失败，请稍后再试");
    //                $.pdialog.closeCurrent();
    //            }
    //        })
    //    }

    function Load() {
        zTree_permission_role = $("#Permission_role_ul_role").zTree(setting_permission_role, zNodes_permission_role);
        zNodes_Permission_role_SelectOrganize = $("#Permission_role_ul_Organize").zTree(setting_Permission_role_SelectOrganize, zNodes_Permission_role_SelectOrganize);
        //zTree_Permission_role_Module = $("#Permission_role_ul_Module").zTree(setting_Permission_role_Module, zNodes_Permission_role_Module);
        //zTree_Permission_role_PermissionItem = $("#Permission_role_ul_PermissionItem").zTree(setting_Permission_role_PermissionItem, zNodes_Permission_role_PermissionItem);
    }

    function Permission_role_bindClick() {
        $("#Permission_role_btn_submit").bind("click", function () {
            $("#background,#progressBar").show();
            //获取选中的角色ID集合
            var submit_roleNodes = zTree_permission_role.getCheckedNodes(true);
            var submit_roleIdList = "";
            for (var i = 0; i < submit_roleNodes.length; i++) {
                submit_roleIdList += submit_roleNodes[i].Id + ",";
            }

            //获取选中的组织机构ID集合
            var submit_organizeNodes = zNodes_Permission_role_SelectOrganize.getCheckedNodes(true);
            var submit_organizeIdList = "";
            for (var i = 0; i < submit_organizeNodes.length; i++) {
                submit_organizeIdList += submit_organizeNodes[i].Id + ",";
            }

            //            //获取选中的菜单ID集合
            //            var submit_moduleNodes=zTree_Permission_role_Module.getCheckedNodes(true);
            //            var submit_moduleIdList="";
            //            for(var i=0;i<submit_moduleNodes.length;i++)
            //            {
            //                submit_moduleIdList+=submit_moduleNodes[i].Id+",";
            //            }

            //            //获取可分配操作权限ID集合
            //            var submit_PermissionItemNodes=zTree_Permission_role_PermissionItem.getCheckedNodes(true);
            //            var submit_PermissionItemIdList="";
            //            for(var i=0;i<submit_PermissionItemNodes.length;i++)
            //            {
            //                submit_PermissionItemIdList+=submit_PermissionItemNodes[i].Id+",";
            //            }

            $.ajax({
                url: "/Permission/Role/SetRoleSelect",
                dataType: "json",
                type: "post",
                data: { roleID: $("#Permission_role_hidden_roleID").val(), rListID: submit_roleIdList, oListID: submit_organizeIdList },
                success: function (data) {
                    if (data.statusCode == "200") {
                        alertMsg.correct(data.message);
                    }
                    else {
                        alertMsg.error(data.message);
                    }
                    $.pdialog.closeCurrent();
                },
                error: function (e) {
                    alertMsg.error("出现异常，请稍后再试!");
                    $.pdialog.closeCurrent();
                }
            });
            $("#background,#progressBar").hide();
        })
    }

    $(document).ready(function () {
        //pageload();已经采用viewBag的方式传值
        Load();
        Permission_role_bindClick();
    });
</script>
<input type="hidden" id="Permission_role_hidden_roleID" value="@Model.Id" />
<input type="hidden" id="Permission_role_hidden_rolelistID" value="@ViewBag.tempRole" />
<input type="hidden" id="Permission_role_hidden_organizeID" value="@ViewBag.tempOrganize" />
@*<input type="hidden" id="Permission_role_hidden_modulelistID" value="@ViewBag.tempModule" />
<input type="hidden" id="Permission_role_hidden_permissionitemlistID" value="@ViewBag.tempPermissionitem" />*@
<div class="page" layouth="40">
    <ul class="searchBar">
        <li>
            <span>角色:</span>
            <i>@Model.Realname</i>
        </li>
        <li>
            <span>数据集权限:</span>
            <i>123456</i>
        </li>
    </ul>
    <div class="tabs">
        <div class="tabsHeader">
            <div class="tabsHeaderContent">
                <ul>
                    <li class="selected"><a href="javascript:void(0)"><span>角色</span></a></li>
                    <li><a href="javascript:void(0)"><span>组织机构(部门)</span></a></li>
                </ul>
            </div>
        </div>
        <div class="tabsContent">
            <div layouth="113">
                <ul id="Permission_role_ul_role" class="ztree">
                </ul>
            </div>
            <div layouth="113">
                <ul id="Permission_role_ul_Organize" class="ztree">
                </ul>
            </div>
        </div>
    </div>
</div>
<div class='formBar'>
    <ul>
        <li>
            <button type="submit" class="btn btn-success btn-sm" id="Permission_role_btn_submit">
                保存</button></li>
        <li>
            <button type="button" class="close btn btn-default btn-sm">
                取消</button></li>
    </ul>
</div>
